package com.example.controller;

import com.example.po.Attendance;
import com.example.service.AttendanceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;
    @RequestMapping("/addAttendance")
    @ResponseBody
    public String addAttendance(@Param("attendance") Attendance attendance){
        if(attendanceService.insertAttendance(attendance)){
            return "输入缺课记录成功";
        }else {
            return "输入缺课记录失败";
        }
    }
    @RequestMapping("/searchAttendances")
    @ResponseBody
    public List<Attendance> searchAttendances(@Param("attendance") Attendance attendance, HttpSession session){
        List<Attendance> attendances= attendanceService.searchAttendance(attendance,session);
        return attendances;
    }

    @RequestMapping("/deleteAttendances")
    @ResponseBody
    public String searchAttendances(Integer id, HttpSession session){

        if(attendanceService.deleteAttendance(id)){
            return "删除缺课记录成功";
        }else{
            return "删除缺课记录失败";
        }
    }
    @RequestMapping("/searchAAttendance")
    @ResponseBody
    public List<Attendance> searchAAttendance(Attendance attendance){
        return  attendanceService.search(attendance);
    }

    @RequestMapping("/updateAttendanceInfo")
    @ResponseBody
    public String updateAttendanceInfo(Attendance attendance){
        if(attendanceService.updateAttendance(attendance)){
            return "修改缺课记录成功";
        }else{
            return "修改缺课记录失败";
        }
    }
    /**
     *查询缺课记录
     */
    @RequestMapping("/attendance")
    @ResponseBody
    public List<Attendance> searchAttendance(Attendance attendance){
        List<Attendance> attendances =attendanceService.findAttendances(attendance);
        return attendances;
    }
}
